package com.hong.servicesms.controller;

import com.alibaba.excel.util.StringUtils;
import com.hong.commonutil.result.Result;
import com.hong.servicesms.service.MsmService;
import com.hong.servicesms.utils.RandomUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/api/msm/")
public class SmsApiController {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Autowired
    private MsmService msmService;
    @ApiOperation("发送手机验证码")
    @GetMapping("send/{phone}")
    public Result send(@PathVariable String phone){
//            code = RandomUtil.getSixBitRandom();
//            boolean isSend= msmService.send(phone,code);
        String code="100866";
        boolean isSend=true;
        if(isSend){
            redisTemplate.opsForValue().set(phone,code,5, TimeUnit.MINUTES);
            return Result.ok();
        }else {
            return Result.fail().message("短信发送失败");
        }
    }
}
